package com.jsj.subway.ai.common;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

@Getter
public enum Role {
    SYS(1,"sys"),
    USER(2,"user"),
    ASSISTANT(3,"assistant");
    private final int roleCode;
    private final String label;

    Role(int code, String label){
        this.roleCode = code;
        this.label = label;
    }

    public static Role valueOf(Integer code){
        return Arrays.stream(Role.values())
                .filter(e -> Objects.equals(e.getRoleCode(), code))
                .findFirst()
                .orElseThrow(() -> new RuntimeException(StrUtil.format("invalid Role: {}", code)));
    }

    public static Role labelOf(String label){
        return Arrays.stream(Role.values())
                .filter(e -> Objects.equals(e.getLabel(), label))
                .findFirst()
                .orElseThrow(() -> new RuntimeException(StrUtil.format("invalid Role: {}", label)));
    }

}
